from django import forms
from web.forms.bootstrap import BootStrapForm
from web import models


class WikiModelForm(BootStrapForm, forms.ModelForm):
    # content = forms.CharField(label='内容')

    class Meta:
        model = models.Wiki
        exclude = ['project', 'depth', ]  # 不选择它 它不显示

    def __init__(self, request, *args, **kwargs):
        super().__init__(*args, **kwargs)
        # 找到想要的数据字敦把它绑定显示的数据重置
        # 让django 不用关联的所以的数据 而用当前项目的所以数据wiki标题【数据库中
        # data_list = models.Wiki.objects.filter(project='当前项目').values_list('id', 'title')

        total_data_list = [('', '请选择-------'), ]  # 要留一个空元素，因为文章要有一级
        data_list = models.Wiki.objects.filter(project=request.bug_platform.project).values_list('id', 'title')

        total_data_list.extend(data_list)
        self.fields['parent'].choices = total_data_list
